package com.jqq.network;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author 姬倩倩
 * @version 1.0
 */
public class InetAddress_ {
    public static void main(String[] args) {
        //1.实例化

        try {
            //getByName(String host):获取指定ip对应的InetAddress实例
            InetAddress inet1 = InetAddress.getByName("112.80.248.75");
            System.out.println(inet1);// /192.168.23.3
            InetAddress inet2 = InetAddress.getByName("www.baidu.com");
            System.out.println(inet2);//www.baidu.com/112.80.248.75

            //getLocalHost()：获取本地ip对应的InetAddress实例
            InetAddress inet3 = InetAddress.getLocalHost();
            System.out.println(inet3);//LAPTOP-MVD4O0VJ/192.168.1.151

            InetAddress inet4 = InetAddress.getByName("127.0.0.1");
            System.out.println(inet4);// /127.0.0.1

            //常用方法
            System.out.println(inet2.getHostName());//www.baidu.com
            System.out.println(inet2.getHostAddress());//112.80.248.75
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
